package com.tdkj.action.backstage.information;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tdkj.action.BaseAction;
import com.tdkj.model.common.BeanType;
import com.tdkj.model.information.BeanBaseInfo;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.information.IBeanFutureService;
import com.tdkj.util.typeconverter.DateTypeConverter;
public class FutureAction  extends BaseAction{
	private Long id;
	private BeanBaseInfo future;
	private String varietyid;
	private String variety;
	private String fullId;
	private Timestamp createtime;
	private IBeanFutureService futureService;
	private Map<String,String>prop=new HashMap<String,String>();
	private List<BeanBaseInfo> futures=new ArrayList<BeanBaseInfo>();
	private String[] ids;
	public String deleteAll() {
		if (null != ids) {
			for (String idtemp : ids) {
				this.getBaseService().delete(Long.parseLong(idtemp), BeanBaseInfo.class);
			}
		}
		return findAll();
	}public String[] getIds() {
		return ids;
	}

	public void setIds(String[] ids) {
		this.ids = ids;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public BeanBaseInfo getFuture() {
		return future;
	}
	public void setFuture(BeanBaseInfo future) {
		this.future = future;
	}
	public String getVarietyid() {
		return varietyid;
	}
	public void setVarietyid(String varietyid) {
		this.varietyid = varietyid;
	}
	public String getVariety() {
		return variety;
	}
	public void setVariety(String variety) {
		this.variety = variety;
	}
	public String getFullId() {
		return fullId;
	}
	public Timestamp getCreatetime() {
		return createtime;
	}
	public void setCreatetime(Timestamp createtime) {
		this.createtime = createtime;
	}
	public void setFullId(String fullId) {
		this.fullId = fullId;
	}
	public Map<String, String> getProp() {
		return prop;
	}
	public void setProp(Map<String, String> prop) {
		this.prop = prop;
	}
	public IBeanFutureService getFutureService() {
		return futureService;
	}
	@Resource
	public void setFutureService(IBeanFutureService futureService) {
		this.futureService = futureService;
	}
	public List<BeanBaseInfo> getFutures() {
		return futures;
	}
	public void setFutures(List<BeanBaseInfo> futures) {
		this.futures = futures;
	}
	public String findAll(){
		return "findAll";
	}
	public String findRightPage(){
		if(fullId!=null){
			String hql = "select bean from " + BeanBaseInfo.class.getName() +" as bean, " + BeanType.class.getName() + " as type "
			+ " where bean.varietyid=type.id and (type.fullId='"+fullId+"' or type.fullId like '"+fullId+"-%')" 
			+ " and bean.moduletype='14' and bean.columntype='1' order by moduletype desc";
			Query query = this.createQuery(hql);
			this.queryByPage(query, "futureAction!findRightPage.action", 10);
		}else{
			Criteria criteria = this.createCriteria(BeanBaseInfo.class);
			criteria.add(Restrictions.eq("moduletype", "14"));
			criteria.add(Restrictions.eq("columntype", "1"));
			criteria.addOrder(Order.desc("moduletype"));// 
			this.queryByPage(criteria, "futureAction!findRightPage.action", 10);
		}
		return "findRightPage";
	}
	public String findRightAddPage(){
		return "findRightAddPage";
	}
	
	public String findRightEditPage(){
		future=futureService.findById(this.getId(),BeanBaseInfo.class);
		return "findRightEditPage";
	}
	
	//添加期货
	public String addFuture(){
		BeanBaseInfo bean=new BeanBaseInfo();
		bean.setClicktime(1);
		bean.setModuletype("14");
		bean.setModulename("行情");
		bean.setColumntype("1");
		bean.setColumnname("期货行情");
		bean.setStatus("未审核");
		bean.setCreatetime(this.getCreatetime());
		bean.setVariety(this.getVariety());
		bean.setVarietyid(this.getVarietyid());
		if(this.getProp()!=null){
			bean.setProp(this.getProp());
		}
		//BeanUser u= (BeanUser) ActionContext.getContext().getSession().get(PublicConfing.MEMBER_MEMBWE_OBJ_STRING_CONFIG);
		BeanUser u=futureService.findById(1l, BeanUser.class);
		bean.setUser(u);
		futureService.save(bean);
		return findAll();
	}
	
	public String editFuture(){
		BeanBaseInfo bean=futureService.findById(this.getId(), BeanBaseInfo.class);
		bean.setVariety(this.getVariety());
		bean.setVarietyid(this.getVarietyid());
		bean.setCreatetime(this.getCreatetime());
		if(this.getProp()!=null){
			bean.setProp(this.getProp());
		}
		futureService.merge(bean);
		return findAll();
	}
	
	public String deleteFuture(){
		futureService.deleteFuture(this.getId());
		return findRightPage();
	}
	
}
